package avicit.bdp.dms.das.rest;

import avicit.bdp.common.service.dto.BdpColumnDTO;
import avicit.bdp.common.service.dto.BdpTableDTO;
import avicit.bdp.common.utils.PageUtils;
import avicit.bdp.dms.das.dto.TableCompareRequestDTO;
import avicit.bdp.dms.das.dto.TableCompareResponseDTO;
import avicit.bdp.dms.das.service.BdpDasColumnService;
import avicit.bdp.dms.das.service.BdpDasTableService;
import avicit.platform6.api.system.ConvertColumnClient;
import avicit.platform6.api.system.impl.SystemConstant;
import avicit.platform6.commons.utils.BusinessUtil;
import avicit.platform6.core.exception.BusinessException;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 模型管理REST接口
 */
@RestController
@Api(tags = "模型管理REST接口")
@RequestMapping("/api/bdp/dms/das/table")
public class BdpDasTableRest {

    @Autowired
    private BdpDasTableService bdpDasTableService;

    @Autowired
    private BdpDasColumnService bdpDasColumnService;

    @Autowired
    private ConvertColumnClient convertColumnClient;


    /**
     * 新增模型对象
     */
    @ApiOperation(value = "新增对象")
    @PostMapping("/insertModel")
    public ResponseMsg<BdpTableDTO> insertModel(@RequestBody BdpTableDTO bdpDasTable) {
        ResponseMsg<BdpTableDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.insertBdpDasTable(bdpDasTable));
        return responseMsg;
    }


    /**
     * 修改模型对象
     */
    @ApiOperation(value = "修改对象")
    @PostMapping("/updateModel")
    public ResponseMsg<Map<String, Object>> updateModel(@RequestBody BdpTableDTO bdpDasTable) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.updateBdpDasTable(bdpDasTable));
        return responseMsg;
    }

    /**
     * 删除模型对象
     */
    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "ids", value = "id集合", dataType = "List", paramType = "body")
    @PostMapping("/deleteModel")
    public ResponseMsg<Integer> deleteByIds(@RequestBody Map<String,Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        String errorInfo = "";
        errorInfo = bdpDasTableService.deleteBdpDasTableByIds(map);
        if (StringUtils.isNotBlank(errorInfo)){
            responseMsg.setRetCode("400");
            responseMsg.setMessage(errorInfo);
        }
        return responseMsg;
    }

    /**
     *@逻辑模型批量删除
     */
    @ApiOperation(value = "批量删除")
    @ApiParam(value = "逗号分隔的id串", name = "ids", required = true)
    @DeleteMapping
    public ResponseMsg<Boolean> batchDelete(@RequestBody String ids) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.batchDelete(ids));
        return responseMsg;
    }


    /**
     * 批量保存模型位置
     */
    @ApiOperation(value = "批量保存模型位置")
    @PostMapping("/saveModelImage")
    public ResponseMsg<Integer> saveModelImage(@RequestBody List<BdpTableDTO> tables) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        bdpDasTableService.saveModelImage(tables);
        return responseMsg;
    }

    /**
     * 判断表名是否重复
     */
    @ApiOperation(value = "判断模型名称是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableId", value = "模型id", dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "tableName", value = "模型名称", dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "typeId", value = "分类id", dataType = "String", paramType = "body")
    })
    @PostMapping("/isSameName")
    public ResponseMsg<Integer> isSameName(@ApiIgnore @RequestBody Map<String, Object> queryMap) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        String tableId = MapUtils.getString(queryMap, "tableId", "");
        String tableName = MapUtils.getString(queryMap, "tableName", "");
        String typeId = MapUtils.getString(queryMap, "typeId", "");
        Integer type = MapUtils.getInteger(queryMap, "type");
        Integer flag = bdpDasTableService.isSameName(tableId, tableName, typeId, type);
        responseMsg.setResponseBody(flag);
        return responseMsg;
    }

    /**
     * 中间节点节点查询模型图形
     * 注意：
     * 1、数据建模，根据分类节点ID查看模型列表，根据登录角色过滤权限，仅包括查看、编辑权限
     */
    @ApiOperation(value = "中间级节点查询模型图形")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "中间节点分类Id", name = "typeId", dataType = "String"),
            @ApiImplicitParam(value = "状态", name = "storeStatus", dataType = "String"),
            @ApiImplicitParam(value = "查询关键字", name = "keyWords", dataType = "String"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Integer"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Integer")
    })
    @GetMapping("/searchMiddleData")
    public ResponseMsg<QueryRespBean<BdpTableDTO>> searchMiddleData(
            @RequestParam String typeId,
            @RequestParam Integer type,
            @RequestParam(required = false) String layerId,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String keyWords,
            @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<BdpTableDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(bdpDasTableService.searchMiddleData(typeId, type, layerId, status, keyWords,
                pageNo, pageSize));

        return responseMsg;
    }

    /**
     * 末级节点查询模型图形
     * 注意：
     * 1、数据建模，末级节点根据分类节点ID查看模型列表
     */
    @ApiOperation(value = "末级节点查询模型图形")
    @ApiImplicitParam(value = "末级节点分类ID", name = "typeId", dataType = "String")
    @GetMapping("/searchDataImage")
    public ResponseMsg<Map<String, Object>> searchDataImage(
            @RequestParam String typeId) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.searchTableImage(typeId));
        return responseMsg;
    }



    /**
     * 模型落库
     */
    @ApiOperation(value = "模型落库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelIds", value = "模型id", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "dataSourceId", value = "数据源id", dataType = "String", paramType = "body", required = true)
    })
    @PostMapping("/insertDB")
    public ResponseMsg<Map<String, List<String>>> insertDataBase(@ApiIgnore @RequestBody Map<String, String> queryMap) {
        ResponseMsg<Map<String, List<String>>> responseMsg = new ResponseMsg<>();
        String modelIds = MapUtils.getString(queryMap, "modelIds", "");
        String datasourceId = MapUtils.getString(queryMap, "dataSourceId", "");
        responseMsg.setResponseBody(bdpDasTableService.insertDataBase(modelIds, datasourceId));
        return responseMsg;
    }


    /**
     * 根据表ID查询字段信息
     */
    @ApiOperation(value = "根据表ID查询字段信息")
    @ApiImplicitParam(value = "模型id", name = "tableId", dataType = "String")
    @GetMapping("/searchByTableId")
    public ResponseMsg<List<BdpColumnDTO>> searchByTableId(
            @RequestParam String tableId) {
        ResponseMsg<List<BdpColumnDTO>> responseMsg = new ResponseMsg<>();
        List<String> tableIdList = new ArrayList<>();
        tableIdList.add(tableId);
        List<BdpColumnDTO> bdpDasColumnDTOList = bdpDasColumnService.searchByTableId(tableIdList);
        responseMsg.setResponseBody(bdpDasColumnDTOList);
        return responseMsg;
    }


    /**
     * 根据项目和分类查询表信息
     */
    @ApiOperation(value = "根据项目和分类查询表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类id", name = "typeId", dataType = "String"),
            @ApiImplicitParam(value = "数据空间id", name = "projectId", dataType = "String"),
            @ApiImplicitParam(value = "查询关键字", name = "keyWords", dataType = "String"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int"),
            @ApiImplicitParam(value = "密级", name = "secretLevel", dataType = "String")
    })
    @GetMapping("/getListForModel")
    public ResponseMsg<QueryRespBean<BdpTableDTO>> getListForModel(
            @RequestParam String typeId,
            @RequestParam String projectId,
            @RequestParam(required = false) String keyWords,
            @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(required = false) String secretLevel) {

        ResponseMsg<QueryRespBean<BdpTableDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<BdpTableDTO> result = bdpDasTableService.getListForModel(typeId, projectId, keyWords, pageNo, pageSize, secretLevel);
        valueConvert(result.getResult());
        responseMsg.setResponseBody(result);
        return responseMsg;
    }


    /**
     * 数据工作台模型新增
     */
    @ApiOperation(value = "新增对象")
    @PostMapping("/insertDataTable")
    public ResponseMsg<Map<String, Object>> insertDataTable(@RequestBody BdpTableDTO bdpDasTable) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.insertDataTable(bdpDasTable));
        return responseMsg;
    }

    /**
     * 修改工作台模型新增
     */
    @ApiOperation(value = "修改对象")
    @PostMapping("/updateDataTable")
    public ResponseMsg<Map<String, Object>> updateDataTable(@RequestBody BdpTableDTO bdpDasTable) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.updateDataTable(bdpDasTable));
        return responseMsg;
    }

    /**
     * 删除工作台模型删除
     */
    @ApiOperation(value = "批量删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "id集合，逗号分隔", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "projectId", value = "数据空间id", dataType = "String", paramType = "body",
                    required = true),
            @ApiImplicitParam(name = "delDB", value = "是否删除物理表", dataType = "int", paramType = "body")
    })
    @PostMapping("/deleteDataTable")
    public ResponseMsg<Integer> deleteDataTable(@ApiIgnore @RequestBody Map<String, String> queryMap) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        String ids = queryMap.get("ids");
        String projectId = queryMap.get("projectId");
        Integer delDB = MapUtils.getInteger(queryMap,"delDB",0);
        bdpDasTableService.deleteDataTable(ids, projectId, delDB);
        return responseMsg;
    }


    /**
     * 通过平台API将字段值转换为名称，包括通用选择组件、通用代码
     */
    private void valueConvert(List<BdpTableDTO> bdpDasTableDTOList) {
        //循环组装请求数据
        Map<String, Set<String>> convertFormData = new HashMap<>();
        for (BdpTableDTO bdpTableDTO : bdpDasTableDTOList) {
            BusinessUtil.createConvertSet(convertFormData, SystemConstant.USER, bdpTableDTO.getCreatedBy());
        }
        if (convertFormData.size() > 0) {
            //获取请求结果
            Map<String, Map<String, String>> convertResultData = convertColumnClient.replace(convertFormData);
            //循环设置Alias或Name的值
            for (BdpTableDTO bdpTableDTO : bdpDasTableDTOList) {
                bdpTableDTO.setUsername(BusinessUtil.convertFormat(convertResultData, SystemConstant.USER,
                        bdpTableDTO.getCreatedBy()));
            }
        }
    }

    /**
     * 查询空间下面导入数据源中的表
     */
    @ApiOperation(value = "查询空间下面导入数据源中的表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数据空间id", name = "projectId", dataType = "String"),
            @ApiImplicitParam(value = "数据源id", name = "dataSourceId", dataType = "String")
    })
    @GetMapping("/selectImportedTable")
    public ResponseMsg<Set<String>> selectImportedTable(@RequestParam String projectId,
                                                        @RequestParam String dataSourceId) {

        ResponseMsg<Set<String>> responseMsg = new ResponseMsg<>();
        List<BdpTableDTO> list = bdpDasTableService.selectTableList(projectId, null, null, null, dataSourceId);
        if (CollectionUtils.isNotEmpty(list)) {
            Set<String> nameSet = list.parallelStream().map(BdpTableDTO::getName).collect(Collectors.toSet());
            responseMsg.setResponseBody(nameSet);
        }

        return responseMsg;
    }


    /**
     * 表结构比对
     */
    @ApiOperation(value = "表结构比对")
    @PostMapping("/modelCompare")
    public ResponseMsg<List<TableCompareResponseDTO>> modelCompare(@RequestBody TableCompareRequestDTO compareDto) {
        ResponseMsg<List<TableCompareResponseDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.modelCompare(compareDto));
        return responseMsg;
    }

    /**
     * 数据源模型导入
     */
    @ApiOperation(value = "数据源模型导入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tables", value = "id", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "typeId", value = "分类id", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "dataSourceId", value = "数据源id", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "type", value = "导入类型", dataType = "int", paramType = "body", required = true)
    })
    @PostMapping(value = "/importModel")
    public ResponseMsg<Map<String, List<String>>> importModel(@ApiIgnore @RequestBody Map<String, Object> queryMap) {

        String tables = MapUtils.getString(queryMap, "tables", "");
        String typeId = MapUtils.getString(queryMap, "typeId", "");
        String dataSourceId = MapUtils.getString(queryMap, "dataSourceId", "");
        int type = MapUtils.getIntValue(queryMap, "type");

        if (StringUtils.isAnyBlank(dataSourceId, tables, typeId)) {
            throw new BusinessException("请检查参数!");
        }

        ResponseMsg<Map<String, List<String>>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.importModel(dataSourceId, tables, typeId, type));

        return responseMsg;
    }

    /**
     * 模型同步
     */
    @ApiOperation(value = "模型同步")
    @PostMapping("/syncModel")
    public ResponseMsg<Map<String, List<String>>> syncModel(@RequestBody List<BdpTableDTO> list) {
        ResponseMsg<Map<String, List<String>>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.syncModel(list));
        return responseMsg;
    }


    /**
     * 查询表列表，并查询表的导入状态
     */
    @ApiOperation(value = "物理模型导入数据源 根据数据源ID获取所有表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数据源id", name = "dataSourceId", dataType = "String"),
            @ApiImplicitParam(value = "分类id", name = "typeId", dataType = "String"),
            @ApiImplicitParam(value = "查询关键字", name = "keyword", dataType = "String"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Integer"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Integer")
    })
    @GetMapping(value = "/getTableListAndStatusByDatasourceId")
    public ResponseMsg<QueryRespBean<BdpTableDTO>> getTableListAndStatusByDatasourceId(
            @RequestParam String dataSourceId,
            @RequestParam String typeId,
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize) throws Exception {

        ResponseMsg<QueryRespBean<BdpTableDTO>> responseMsg = new ResponseMsg<>();

        List<String> typeList = new ArrayList<>();
        if (StringUtils.isNoneBlank(typeId)) {
            typeList.add(typeId);
        }
        List<BdpTableDTO> result =
                bdpDasTableService.getTableListAndStatusByDatasourceId(dataSourceId, typeList, keyword);
        QueryRespBean<BdpTableDTO> queryRespBean = new QueryRespBean<>();
        queryRespBean.setResult(PageUtils.listConvertToPage(pageNo, pageSize, result));
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    /**
     * 判断数据表中是否有数据
     */
    @ApiOperation(value = "判断数据表中是否有数据")
    @ApiImplicitParam(value = "模型表ID", name = "tableId", dataType = "String")
    @GetMapping("/tableData")
    public ResponseMsg<Integer> tableData(@RequestParam String tableId) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.tableData(tableId));
        return responseMsg;
    }


    /**
     * 批量修改分类
     */
    @ApiOperation(value = "批量修改分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableIds", value = "模型id集合", dataType = "List", paramType = "body", required = true),
            @ApiImplicitParam(name = "typeId", value = "分类id", dataType = "String", paramType = "body", required = true),
            @ApiImplicitParam(name = "projectId", value = "数据空间id", dataType = "String", paramType = "body" , required = true)
    })
    @PostMapping("/updateType")
    public ResponseMsg<String> updateType(@ApiIgnore @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        bdpDasTableService.updateType(map);
        return responseMsg;
    }

    /**
     * 根据id获取表信息以及字段信息
     */
    @ApiOperation(value = "根据id获取表信息以及字段信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "模型id", name = "tableId", dataType = "String"),
            @ApiImplicitParam(value = "数据空间id", name = "projectId", dataType = "String")
    })
    @GetMapping("/getTableById")
    public ResponseMsg<BdpTableDTO> getTableById(@RequestParam String tableId,
                                                 @RequestParam(required = false) String projectId) {
        ResponseMsg<BdpTableDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.getTableById(tableId, projectId));
        return responseMsg;
    }

    @ApiOperation(value = "启用/停用")
    @PostMapping("/updateStatus")
    public ResponseMsg<Boolean> updateStatus(@RequestBody BdpTableDTO bdpTableDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        bdpDasTableService.updateStatus(bdpTableDTO.getIds(), bdpTableDTO.getStatus());
        return responseMsg;
    }


    @ApiOperation(value = "物理模型选择逻辑模型")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "模型id", name = "sourceTableId", dataType = "String")
    })
    @GetMapping("/importLogicModel")
    public ResponseMsg<BdpTableDTO> importLogicModel(@RequestParam String sourceTableId) {
        ResponseMsg<BdpTableDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.importLogicModel(sourceTableId));
        return responseMsg;
    }

    @ApiOperation(value = "物理模型选择逻辑模型切换数据源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "模型id", name = "sourceTableId", dataType = "String"),
            @ApiImplicitParam(value = "数据源类型", name = "dataSourceType", dataType = "String")
    })
    @GetMapping("/changeColumnType")
    public ResponseMsg<List<BdpColumnDTO>> changeColumnType(@RequestParam String sourceTableId,@RequestParam String dataSourceType) {
        ResponseMsg<List<BdpColumnDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.changeColumnType(sourceTableId,dataSourceType));
        return responseMsg;
    }

    @ApiOperation(value = "逻辑模型导入物理模型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sourceTableIds", value = "导入模型id", dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "categoryId", value = "主题id", dataType = "String", paramType = "body")
    })
    @PostMapping("/importPhysicalModel")
    public ResponseMsg<List<String>> importPhysicalModel(@RequestBody Map<String,Object> queryMap) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        String sourceTableIds = MapUtils.getString(queryMap, "sourceTableIds", "");
        String categoryId = MapUtils.getString(queryMap, "categoryId", "");
        responseMsg.setResponseBody(bdpDasTableService.importPhysicalModel(sourceTableIds,categoryId));
        return responseMsg;
    }

    @GetMapping("/compareTableVersion")
    @ApiOperation(value = "模型版本对比")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "版本模型id1", name = "leftTableId", dataType = "String"),
            @ApiImplicitParam(value = "版本模型id2", name = "rightTableId", dataType = "String")
    })
    public ResponseMsg<Map<String,Object>> compareTableVersion(@RequestParam String leftTableId,@RequestParam String rightTableId) {
        ResponseMsg<Map<String,Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(bdpDasTableService.compareTableVersion(leftTableId,rightTableId));
        return responseMsg;
    }

    @ApiOperation(value = "物理模型引用标准类型修改")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "字段类型", name = "columns", dataType = "String"),
            @ApiImplicitParam(value = "数据源类型", name = "dataSourceType", dataType = "String")
    })
    @PostMapping("/physicalChangeColumnType")
    public ResponseMsg<List<BdpColumnDTO>> physicalChangeColumnType(@RequestBody Map<String,Object> queryMap) {
        ResponseMsg<List<BdpColumnDTO>> responseMsg = new ResponseMsg<>();
        List<Map<String,Object>> columns = (List<Map<String, Object>>) queryMap.get("columns");
        String dataSourceType = (String) queryMap.get("dataSourceType");
        responseMsg.setResponseBody(bdpDasTableService.physicalChangeColumnType(columns,dataSourceType));
        return responseMsg;
    }

    @ApiOperation(value = "导入元数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sourceTableIds", value = "导入模型id", dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "modelType", value = "模型类型", dataType = "Integer", paramType = "body"),
            @ApiImplicitParam(name = "categoryId", value = "主题id", dataType = "String", paramType = "body")
    })
    @PostMapping("/importMetadataTable")
    public ResponseMsg<List<String>> importMetadataTable(@RequestBody Map<String,Object> queryMap) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        String sourceTableIds = MapUtils.getString(queryMap, "sourceTableIds", "");
        Integer modelType =  MapUtils.getInteger(queryMap,"modelType");
        String categoryId = MapUtils.getString(queryMap, "categoryId", "");
        responseMsg.setResponseBody(bdpDasTableService.importMetadataTable(sourceTableIds,modelType,categoryId));
        return responseMsg;
    }

    //逻辑模型导入物理模型列表
    @ApiOperation(value = "导入列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类", name = "typeId", dataType = "String"),
            @ApiImplicitParam(value = "分类", name = "dataSourceId", dataType = "String"),
            @ApiImplicitParam(value = "被导入的类型", name = "type", dataType = "String"),
            @ApiImplicitParam(value = "导入后的类型", name = "importType", dataType = "String"),
            @ApiImplicitParam(value = "查询关键字", name = "keyWords", dataType = "String"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Integer"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Integer")
    })
    @GetMapping("/searchImportList")
    public ResponseMsg<QueryRespBean<BdpTableDTO>> searchImportList(
            @RequestParam(required = false) String typeId,
            @RequestParam(required = false) String dataSourceId,
            @RequestParam Integer type,
            @RequestParam Integer importType,
            @RequestParam(required = false) String sourceTypeId,
            @RequestParam(required = false) String keyWords,
            @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<BdpTableDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(bdpDasTableService.searchImportList(typeId, dataSourceId, type, importType, sourceTypeId, keyWords,
                pageNo, pageSize));

        return responseMsg;
    }
}
